package net.hky365.shop.module.system.service.user;

import lombok.RequiredArgsConstructor;
import net.hky365.shop.framework.common.enums.UserTypeEnum;
import net.hky365.shop.framework.security.core.api.oauth2.UserApi;
import net.hky365.shop.framework.tenant.core.aop.TenantIgnore;
import net.hky365.shop.module.system.dal.mysql.user.AdminUserMapper;
import net.hky365.shop.module.system.service.member.MemberService;
import org.springframework.stereotype.Component;

/**
 * 用户 API 实现类
 */
@Component
@RequiredArgsConstructor
public class UserApiImpl implements UserApi {
    private final AdminUserMapper adminUserMapper;
    private final MemberService memberService;

    @TenantIgnore
    public <T extends UserApi.UserInfo> T getUserById(long id, UserTypeEnum userType) {
        if (UserTypeEnum.ADMIN.equals(userType)) {
            return (T) adminUserMapper.selectById(id);
        } else if (UserTypeEnum.MEMBER.equals(userType)) {
            return (T) memberService.getMember(id);
        }
        return null;
    }
}
